//
//  XQTabBarVController.m
//  Glowworm
//
//  Created by 王伟楠 on 2018/8/13.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "XQTabBarVController.h"

#import "XQNavigationVController.h"

#import "XQHomeVController.h"
#import "XQChoiceVController.h"
#import "XQMiddleViewController.h"
#import "XQMenuVController.h"
#import "XQMineVController.h"

@interface XQTabBarVController ()

@end

@implementation XQTabBarVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.backgroundImage = [UIImage imageNamed:@"tab_white"];
    self.tabBar.translucent = NO;
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setShadowImage:[UIImage imageWithColor:[UIColor whiteColor]]];
    
    XQHomeVController *homeVC = [XQHomeVController new];
    [self addChildViewController:homeVC imageName:@"b_bar_01" title:@"首页"];
    
    XQChoiceVController *choiceVC = [XQChoiceVController new];
    [self addChildViewController:choiceVC imageName:@"b_bar_02" title:@"选择"];
    
    XQMiddleViewController *middleVC = [XQMiddleViewController new];
    [self addChildViewController:middleVC imageName:@"b_bar_03" title:@""];
    
    XQMenuVController *menuVC = [XQMenuVController new];
    [self addChildViewController:menuVC imageName:@"b_bar_04" title:@"菜单"];
    
    XQMineVController *mineVC = [XQMineVController new];
    [self addChildViewController:mineVC imageName:@"b_bar_05" title:@"我"];
    
}

//添加子控制器,设置标题与图片
- (void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)imageName title:(NSString *)title{
    
    //设置选中与未选中的图片-->指定一下渲染模式-->图片以原样的方式显示出来
    childCtrl.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_s",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置标题
    //    childCtrl.tabBarItem.title = title;
    //    childCtrl.navigationItem.title = title;
//    childCtrl.title = title;
    
    childCtrl.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
    //指定一下属性
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
    //指定字体
    dic[NSFontAttributeName] = [UIFont systemFontOfSize:16];
    
    //指定选中状态下文字颜色
    [childCtrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    XQNavigationVController *navCtrl = [[XQNavigationVController alloc] initWithRootViewController:childCtrl];
    [self addChildViewController:navCtrl];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
